package com.bodu.exchange.service.impl;

import com.bodu.exchange.entity.vo.ExchangeBookVo;
import com.bodu.core.entity.ParamReq;
import com.bodu.exchange.entity.request.ExchangeBookRequest;
import com.bodu.exchange.mapper.ExchangeBookMapper;
import com.bodu.exchange.service.ExchangeBookService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
* 记账本 Service impl
* @author Administrator
*/
@Service
public class ExchangeBookServiceImpl implements ExchangeBookService {

   @Resource
   private ExchangeBookMapper exchangeBookMapper;

   @Override
   public ExchangeBookVo getModel(Long id) {
      return  exchangeBookMapper.getModel(id);
   }

   @Transactional
   @Override
   public Long save(ExchangeBookRequest request) {
      exchangeBookMapper.save(request);
      return request.getId();
   }

   @Transactional
   @Override
   public Long update(ExchangeBookRequest exchangeBookRequest) {
      exchangeBookMapper.update(exchangeBookRequest);
      return exchangeBookRequest.getId();
   }

   @Override
   public List<ExchangeBookVo> listPage(ParamReq<ExchangeBookRequest> params) {
      params.setStartIndex((params.getCurrent() -1 ) * params.getSize());
      return exchangeBookMapper.listPage(params);
   }

   @Override
   public Integer countPage(ParamReq<ExchangeBookRequest> params) {
       return exchangeBookMapper.countPage(params);
   }

   @Override
   public Integer updateDelFlagById(Long id, Integer delFlag) {
       return exchangeBookMapper.updateDelFlagById(id, delFlag);
   }

   @Override
   public List<ExchangeBookVo> bookList(ExchangeBookRequest exchangeBookRequest) {
      return exchangeBookMapper.bookList(exchangeBookRequest);
   }

    @Override
    public Integer updateDefaultFlagByUserId(Long userId, Integer defaultFlag) {
      return exchangeBookMapper.updateDefaultFlagByUserId(userId, defaultFlag);
    }

    @Override
    public Integer updateDefaultExchangeBookStatus(Long id, Integer defaultFlag) {
       return exchangeBookMapper.updateDefaultExchangeBookStatus(id, defaultFlag);
    }
}
